package com.bjpowernode.boss.convert;

import cn.hutool.core.util.StrUtil;
import com.bjpowernode.boss.common.enums.PublicStatus;
import com.bjpowernode.boss.convert.help.CommonFun;
import com.bjpowernode.boss.dao.entity.UserInfo;
import com.bjpowernode.boss.mvc.models.vo.user.UserInfoVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;

import java.util.List;

@Mapper(componentModel = "spring",uses = {CommonFun.class})
public interface UserConvert {


    List<UserInfoVo>  toListUserInfoVo(List<UserInfo> userInfos);
    @Mappings({
            @Mapping(source = "createTime", target = "createTime", dateFormat = "yyyy-MM-dd HH:mm:ss"),
            @Mapping(source = "status", target = "status", qualifiedByName = "transPublicStatus1")
    })
    UserInfoVo mapUserInfoVo(UserInfo userInfo);

    @Named("transPublicStatus")
    default String transPublicStatus(String status) {
        if (StrUtil.isBlank(status)) {
            return "";
        }
        try {
            PublicStatus publicStatus = PublicStatus.valueOf(status);
            return publicStatus.getMsg();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "未知";
    }
}
